package com.atrix.CinemaView.config;

import com.atrix.CinemaView.exception.MessageException;
import com.atrix.CinemaView.exception.ParamErrorException;
import com.atrix.CinemaView.pojo.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(MessageException.class)
    public R<Void> processMessageException(MessageException e) {
        return R.error(e.getMessage());
    }
    
    @ExceptionHandler(ParamErrorException.class)
    public R<Void> processParamErrorException(ParamErrorException e) {
        return R.error(e.getMessage());
    }
    
    @ExceptionHandler(RuntimeException.class)
    public R<Void> processRuntimeException(RuntimeException e) {
        log.error("未知异常：" + e.getMessage(), e);
        return R.error("系统异常，请稍后再试");
    }
}
